﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL.Entity;
using DAL.Persistencia;
using NewTierra.App_Code;

namespace NewTierra.Pages
{
    public partial class Index1 : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            Response.AddHeader("Last-Modified", DateTime.Now.ToString());
            Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
            Response.AddHeader("Pragma", "no-cache");

            base.PageLoad();
            switch (base.ObterPerfilLogado())
            {
                case (int)PerfilUsuario.Financeiro:
                case (int)PerfilUsuario.Gerencial:
                    lnkUserManager.Enabled = false;
                    break;
                case (int)PerfilUsuario.Operacional:
                    lnkUserManager.Enabled = false;
                    lnkFinanceiro.Enabled = false;
                    lnkCOntasReceber.Enabled = false;
                    break;
                default:
                    break;
            }

            if (!IsPostBack)
            {
                //CalendarioIndex.SelectedDate = DateTime.Now;
                PegaUsuario();
            }
        }

        #region Regras

        protected void PegaUsuario()
        {
            Usuario u = Session[Convert.ToString(Session["emailLogado"])] as Usuario;

            if (u == null)
            {
                Response.Redirect("/Pages/Login.aspx");
            }

            if (u.Cliente_id != null)
            {
                lnkFinanceiro.Enabled = false;
                lnkCOntasReceber.Enabled = false;
                lnkCadastrosSimples.Enabled = false;
                lnkSupplier.Enabled = false;
                lnkServicos.Enabled = false;
                lnkCustos.Enabled = false;
                lnkUserManager.Enabled = false;
            }


            lblBemVindo.Text = u.US_nome;
            lblPerfil.Text = u.Usuario_Perfil.Perfil_tipo;
        }

        #endregion

        #region Links

        protected void Sair(object sender, EventArgs e)
        {
            //Session.Remove(Convert.ToString(Session["emailLogado"]));
            //Session.RemoveAll();

            Session.Abandon();

            FormsAuthentication.SignOut();

            Response.Redirect("~/Pages/Login.aspx");
        }

        protected void ParaSupplier(object sender, EventArgs e)
        {
            Response.Redirect("PSupplier/SupplierConsulta.aspx");
        }

        protected void ParaServicos(object sender, EventArgs e)
        {
            Response.Redirect("Servicos/ServicosConsulta.aspx");
        }

        protected void ParaCliente(object sender, EventArgs e)
        {
            Response.Redirect("Cliente/ClienteConsulta.aspx");
        }

        protected void ParaUserManager(object sender, EventArgs e)
        {
            Response.Redirect("Usuarios/UsuarioConsult.aspx");
        }

        protected void ParaCashFlow(object sender, EventArgs e)
        {
            Response.Redirect("Financas/cash_flow.aspx");
        }

        protected void ParaMontarServico(object sender, EventArgs e)
        {
            Response.Redirect("MontarServicos/MontarServicoConsulta.aspx");
        }

        protected void ParaCadastrosSimples(object sender, EventArgs e)
        {
            Response.Redirect("Tools/AddCadastrosSimples.aspx");
        }

        protected void ParaOperacoes(object sender, EventArgs e)
        {
            //Response.Redirect("~/Pages/Operacoes/CotationConsulta.aspx");
            Response.Redirect("~/Pages/Operacoes/QuoteConsulta.aspx");
        }

        protected void ParaOperacoesNew(object sender, EventArgs e)
        {            
            Response.Redirect("~/Pages/Operacoes/QuoteConsultaNew.aspx");
        }

        protected void ParaFinanceiro(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/Financeiro/CadastroCusto.aspx");
        }

        protected void ParaContasReceber(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/Financeiro/ContasReceber.aspx");
        }

        protected void ParaPacotes(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/CPacote/PacoteConsulta.aspx");
        }

        #endregion

        protected void btnContinueWorking_Click(object sender, EventArgs e)
        {
            //Do nothing.  But the Session will be refreshed as a result of this method being called, which is its purpose.
        }

        protected void lnkTierraAdm_Click(object sender, EventArgs e)
        {

        }       
    }
}